package cn.hnbjx.prepaid.controller;

import cn.hnbjx.prepaid.pojo.*;
import cn.hnbjx.prepaid.service.AccountService;
import cn.hnbjx.prepaid.service.RescueUserService;
import cn.hnbjx.prepaid.service.UserHelpService;
import cn.hnbjx.prepaid.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserHelpController {
    @Autowired
    private UserHelpService userHelpService;
    @Autowired
    private AccountService accountService;
    @Autowired
    private RescueUserService rescueUserService;
    @GetMapping("/admin/userhelp/list")
    public Result list(int page,String key) {
        return Result.ok(userHelpService.findAll(page,key));
    }
    @GetMapping("/api/userhelp/list")
    public Result list(int page,int type,int id) {
        System.out.println("page=="+page);
        System.out.println("type=="+type);
        System.out.println("id=="+id);
        return Result.ok(userHelpService.apifindAll(page,type,id));
    }
    @GetMapping("/api/userhelp/add")
    public Result add(Integer accountId,String address,String location,Integer flag ,String city) {
        System.out.println("accountId=="+accountId);
        UserHelp userHelp=new UserHelp();
        userHelp.setAccountId(accountId);
        userHelp.setAddress(address);
        userHelp.setLocation(location);
        userHelp.setFlag(flag);
        userHelp.setCity(city);
        userHelpService.insert(userHelp);
        return Result.ok("操作成功");
    }

    /**
     *  获取机构和求救用户列表 (按省份查询)
     */
    @GetMapping("/api/data/list")
    public Result list(String province) {
        System.out.println("province=="+province);
        ApiData apiData=new ApiData();
        apiData.setRescueUser(accountService.findByProvince(province));
        apiData.setUserHelp(userHelpService.findByProvince(province));
        return Result.ok(apiData);
    }
    /**
     *  获取机构和求救用户列表 (按省份查询)
     */
    @GetMapping("/api/admin_data/list")
    public Result list() {
        ApiAdminData apiData=new ApiAdminData();
        apiData.setRescueUser(accountService.findByProvince(""));
        apiData.setUserHelp(userHelpService.findByProvince(""));
        List<NumData> qNum= userHelpService.findByNum();
        List<NumData> hNum= rescueUserService.findByNum();
        apiData.setQiuNum(qNum);
        apiData.setJiuNum(hNum);
        return Result.ok(apiData);
    }
}
